package com.wingsfrog.travel.modules.dao;

import com.wingsfrog.travel.controller.dto.response.MainTaskResDto;
import com.wingsfrog.travel.modules.entity.MainTask;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

/**
 * Created by rankin on 16/3/30.
 */
public interface MainTaskDao extends CrudRepository<MainTask, Integer> {
    @Query("select sum(t.taskScore) as score,m.id as id,m.mainTaskName as mainTaskName, m.minCount as minCount, " +
            " m.description as mainTaskDescription, m.type as type   " +
            " from MainTask m, Task t " +
            " where t.mainTaskId = m.id " +
            " group by m.id")
    public List<MainTaskResDto> findTasks();

    @Query("select count(t) from MainTask t, User u,UserTeamRel utr,TeamInfo ti where t.id = ti.mainTaskId and utr.teamId = ti.id and utr.userId = u.id and u.id = ?1 and t.id =  ?2")
    public Long findCountByUserIdAndMainTaskId(Integer userId,Integer mainTaskId);


}
